<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Morder extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function getOrderDB($number,$offset)
    {
        $id = $this->getParamUri(3,2);
        $limit = $offset ? intval($offset) : '0';
        
        $sql = "SELECT *,DATE_FORMAT(created, '%H:%i:%s %d-%m-%Y') AS time FROM cart_order WHERE 1=1 AND del = 0 ";
        $key = $this->getParamString('keyword');
        if(!in_array($key, array(null, '', '0')))
        {
            $sql .= " AND (fullname like '%".$key."%' OR ";
            $sql .= " phone like '%".$key."%' OR ";
            $sql .= " address like '%".$key."%') ";
        }
        $sql .= "ORDER BY id DESC";
        
        $xdata = " LIMIT ".$limit.",".$number." ";
        $xs = $this->db->query($sql.$xdata)->result_object();
        $count = $this->db->query($sql)->num_rows();
        return array('data' => $xs, 'count' => $count);
        
    }
    
    public function getCate($id = 0)
    {
        $data = $this->db->query('SELECT * FROM categories ORDER BY order_by ASC')->result_object();
        $html  = '';
        foreach($data AS $el=>$le)
        {
            if($id == $le->id)
            {
                $selected = 'selected="selected"';
            }else{
                $selected = '';
            }
            $html .= '<option value="'.$le->id.'" '.$selected.'>'.$le->title.'</option>';
        }
        return $html;
    }
    
    
    public function getNamecate()
    {
        return $this->db->query("SELECT * FROM categories ORDER BY order_by ASC")->result_object();
    }
    
    public function deleteProductDB($user)
    {
        $id = $this->getParamInt('id');
        $this->db->update('cart_order', array('del' => 1, 'user' => $user), "id = ".$id);
        return 200;
    }
    
    public function getdetail($id)
    {
        
        $this->db->update('cart_order', array('stt' => 1), "id = ".$id);
        return $this->db->query('SELECT *,DATE_FORMAT(created, "%H:%i:%s %d-%m-%Y") AS time FROM cart_order WHERE del = 0 AND id = '.$id)->row_object();
        
    }
    
    public function getInfo()
    {
        return $this->db->query('SELECT * FROM html WHERE id = 2')->row_object();
    }
    
    public function addInfo()
    {
        //die(addslashes($_REQUEST['content']).'df');
        $this->db->update('html', array('htmlcontent' => addslashes($_REQUEST['content'])), "id = 2");
    }
    
    
}